package com.wn.demo06;

import java.util.Comparator;
import java.util.function.BiFunction;

/**
 * @author yellow Docter
 * @date 2024 -06-18
 * @desc
 *   方法的引用
 *      类名::静态方法
 */
public class Demo02 {

    public static void main(String[] args) {

//        test03();

        //比较器接口
        //Integer.compare(x,y) 中的方法 （比较数值的方法 ）
        Comparator<Integer> com1 = (x,y)-> Integer.compare(x,y);
        int compare = com1.compare(3, 4);
        System.out.println("compare = " + compare);

        //方法引用的写法
        Comparator<Integer> com2 = Integer::compare;
        int compare2 = com1.compare(3, 4);
        System.out.println("com2 = " + com2);

    }

    private static void test03() {
        //lambda 表达式的写法
//        BiFunction<Double,Double,Double> biFunction = (x,y)-> x > y ? x : y;
        BiFunction<Double,Double,Double> biFunction = (x,y)-> Math.max(x,y);
        Double apply = biFunction.apply(3.2d, 4.2d);
        System.out.println("apply = " + apply);

        //方法的引用
        //类名::方法的名称
        BiFunction<Double,Double,Double> biFunction2 = Math::max;
        Double apply2 = biFunction.apply(5.2d, 4.2d);
        System.out.println("apply2 = " + apply2);
    }

}
